<?php
/**
 * View EVENTI - index LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    17-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript">
    //<![CDATA[
     
    $(document).ready(function()
    {
        var paginator =	$('#live-list').pagination({
	    'targetUrl' : '/admin/ajax/select/live',
	    'orderField' : 'live_date',
	    'orderDir' : 'asc',
            'perPage': 3,
            'selected':  <?php echo json_encode( array_keys( (array)$this->data['live'] ) ) ?>
	    },callback // CallBack
	);

        function callback(){
            $('tr[class~="selectable"]').click(function(){
                var id = $(this).attr('id');
                $(".loader").fadeIn();
                $.ajax({
                    url: '/admin/ajax/add/livetoevent/live_id/'+id+'/event_id/<?php echo $this->event_id ?>',
                    dataType: "json",
                    context: document.body
                    }).success(function(data) {
                        $(".loader").fadeOut();

                        if(!data.error)
                        {
                            $('strong#tot').html(data.tot);
                            paginator.setOption('selected', data.live);
                            paginator.refresh();
                        }
                        else
                        {
                            $('li#errorLi').show();
                            $('li#errorLi p#errorMsg').html(obj.responseText);
                        }
                        //$('#selected_locations').append(data);
                        //unselectable();
                    }).error(function(obj,text,error) {
                        //show error
                        $('li#errorLi').show();
                        $('li#errorLi p#errorMsg').html(obj.responseText);
                    });
                })

                //$(this).siblings().removeClass('selected');
                //$(this).addClass('selected');
                //$("input#event_check_"+ id.substr(6,id.length)).attr('checked', true);
                //paginator.refresh();
                //unselectable();
            //});

            $('tr[class~="selected"]').click(function(){
                var id = $(this).attr('id');
                $(".loader").fadeIn();
                $.ajax({
                    url: '/admin/ajax/remove/livefromevent/live_id/'+id+'/event_id/<?php echo $this->event_id ?>',
                    dataType: "json",
                    context: document.body
                    }).success(function(data) {
                        $(".loader").fadeOut();

                        if(!data.error)
                        {
                            $('strong#tot').html(data.tot);
                            paginator.setOption('selected', data.live);
                            paginator.refresh();
                        }
                        else
                        {
                            $('li#errorLi').show();
                            $('li#errorLi p#errorMsg').html(obj.responseText);
                        }
                        //$('#selected_locations').append(data);
                        //unselectable();
                    }).error(function(obj,text,error) {
                        //show error
                        $('li#errorLi').show();
                        $('li#errorLi p#errorMsg').html(obj.responseText);
                    });
//                $(this).removeClass('selected');
//                $("input#event_check_"+ id.substr(6,id.length)).attr('checked', false);
//
//                selectable();
            })
        };
    });

    //]]>
</script>
<div id="content">
    <div id="summary" class="events">
	<div class="head">
	    <h2>
		<?php echo $this->event_types[$this->data['event_type']]['event_type_name'];?>
	    </h2>
	</div>
	<div class="body">
	    <table cellspacing="0" class="table">
		<tbody>
		    <tr>
			<th>Titolo:</th>
			<td>
			    <strong>
				<?php echo $this->data['event_title'] ?>
			    </strong>
			</td>
		    </tr>
		</tbody>
	    </table>
	</div>
    </div>
    <form>
	<ul>
	    <li class="paging-context ">
		<table class="pgStyle1 circle2" cellspacing="0">
		    <tr>
			<td class="c">
			    <var>1</var>
			</td>
			<td class="t">
                            <b id="pagecircle1"><a href="/admin/eventi/info/id/<?php echo $this->event_id ?>">Info Evento/Rassegna</a></b>
			</td>
			<td class="c selected">
			    <var>2</var>
			</td>
			<td class="t selected">
			    <b id="pagecircle2">Scegli Live</b>
			</td>
			<td class="c">
			    <var>3</var>
			</td>
			<td class="t">
			    <b id="pagecircle2">Fine!</b>
			</td>			
		    </tr>
		</table>
	    </li>
	</ul>
    </form>    
    <div class="help">
	<h2>Live:</h2>
	<br/>
        Seleziona i live da associare alla rassegna dall'elenco.
    </div>
    <form>
        <ul>
            <li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none' ?>">
                <h3 id="errorMsgLbl">Si &egrave; verificato un problema durante l'invio del modulo.</h3>
                <p id="errorMsg">
                    <?php var_dump( $this->errorMsg ) ?>
                </p>
            </li>	
        </ul>
    </form>
    <table class="log clearfix list">
        <caption>
            Questo evento contiene <strong id="tot"><?php echo $this->tot ?></strong> live.
        </caption>
        <thead>
            <tr>
                <td class="pagination" colspan="4">
                    <a class="prev" href="javascript: void(0);">&nbsp;</a>
                    <span class="loader">Sto caricando...</span>
                    <a class="next" href="javascript: void(0);">&nbsp;</a>
                </td>
            </tr>
        </thead>
        <tbody id="live-list">
            <!-- Questo contenuto verrà rimpiazzato dalla paginazione -->
        </tbody>
        <tfoot>
            <tr>
                <td class="pagination" colspan="4">
                    <a class="prev" href="javascript: void(0);">&nbsp;</a>
                    <span class="loader">Sto caricando...</span>
                    <a class="next" href="javascript: void(0);">&nbsp;</a>
                </td>
            </tr>
        </tfoot>        
    </table>
</div>
<form id="form-invia" class="fab" method="post" action="/admin/eventi/riepilogo/id/<?php echo $this->event_id ?>">
    <div id="formButtons">
        <button id="salva" type="submit" name="salva" value="salva" class="button positive">
            <img src="/images/admin/tick.png" alt="" />Conferma
        </button>
        <button id="annulla" name="annulla" value="annulla" class="button negative">
            <img src="/images/admin/cross.png" alt="" />Indietro
        </button>
    </div>
</form>